<template>
  <!-- 海报位组件属性 -->
  <div class="detailBoxAttr">
    <div class="comInfo">
      <div class="item1">
        <div class="label">位置：</div>
        <div class="item">
          <div class="infoCon">
            <div class="con" style="margin-right:20px;">
              <span>x：</span>
              <el-input v-model.number="list.style.x" :disabled="ispreview"></el-input>
            </div>
            <div class="con">
              <span>y：</span>
              <el-input v-model.number="list.style.y" :disabled="ispreview"></el-input>
            </div>
          </div>
        </div>
      </div>
      <div class="item1">
        <div class="label">大小：</div>
        <div class="item">
          <div class="infoCon">
            <div class="con" style="margin-right:20px;">
              <span>w：</span>
              <el-input v-model.number="list.style.w" :disabled="ispreview"></el-input>
            </div>
            <div class="con">
              <span>h：</span>
              <el-input v-model.number="list.style.h" :disabled="ispreview"></el-input>
            </div>
          </div>
          <div id="tipMsg" style="marginLeft:25px;color:red;display:none;">组件最大宽度为1115px</div>
        </div>
      </div>
      <div class="item1">
        <div class="label">楼层名称：</div>
        <div class="item">
          <div class="infoCon">
            <el-input v-model.number="list.floorName" :disabled="ispreview"></el-input>
          </div>
        </div>
      </div>
      <div class="item1">
        <div class="label">楼层编码：</div>
        <div class="item">
          <div class="infoCon">
            <el-input v-model.number="list.floorNum" :disabled="ispreview"></el-input>
          </div>
        </div>
      </div>
      <div class="item1">
        <div class="label">焦点位置：</div>
        <div class="item">
          <div class="infoCon">
            <el-input v-model.number="list.value[0].index" :disabled="ispreview"></el-input>
          </div>
          <div id="tipMsg1" style="color:red;display:none;">焦点位置：不能为0，最小从1开始</div>
        </div>
      </div>
      <div class="item2" style="border:none;">
        <div class="label">推荐位置：</div>
        <div class="infoCon">
          <el-radio-group v-model="list.isShow" @change="onChange" :disabled="ispreview">
            <el-radio :label="0">展示</el-radio>
            <el-radio :label="1">取消</el-radio>
          </el-radio-group>
        </div>
      </div>
      <div class="item3" v-if="list.isShow == 0">
        <el-button class="addBtn" type="primary" size="mini" round @click="AddItem">添加</el-button>
        <div class="infoItem" v-if="list.recommendList.length > 0">
          <div class="items" v-for="(item, idx) in list.recommendList" :key="'b' + idx">
            <div class="name">位置{{ idx + 1 }}：</div>
            <div class="con">
              <div>
                <div>位置名称：</div>
                <el-input v-model="item.name" :disabled="ispreview"></el-input>
              </div>
              <div>
                <div>焦点位置：</div>
                <el-input v-model="item.index" :disabled="ispreview"></el-input>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'detailBoxAttr',
  components: {},
  props: {
    comData: {
      type: Object,
      default: () => { }
    },
    ispreview: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      list: this.comData,
      index: '',
      name: '',
    }
  },
  computed: {},
  watch: {
    'list.style': {
      handler(val) {
        if (val.w > 1115) {
          // this.$message.error('组件宽度最大为1115');
          document.getElementById('tipMsg').style.display = 'block';
          setTimeout(() => {
            document.getElementById('tipMsg').style.display = 'none';
            this.list.style.w = 1115;
            this.list.style.x = 4;
            this.list.style.y = 5;
          }, 2000)
        }
      },
      deep: true,
    },
    'list.value': {
      handler(val) {
        if (val[0].index == 0) {
          // this.$message.error('位置排序不能为0，至少从1开始');
          document.getElementById('tipMsg1').style.display = 'block';
          setTimeout(() => {
            document.getElementById('tipMsg1').style.display = 'none';
            this.list.value[0].index = 1;
          }, 2500)
        }
      },
      deep: true,
    }
  },
  methods: {
    onChange() {
      this.$emit('recommend', this.list.isShow)
    },
    AddItem() {
      this.list.recommendList.push({
        name: this.name, index: this.index,
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.detailBoxAttr {
  .comInfo {
    margin: 10px 5px;

    .item1 {
      display: flex;
      flex-direction: row;
      align-items: center;
      justify-content: space-between;
      padding: 10px;
      border-bottom: 1px dashed #dbdbdb;
    }

    .item2 {
      display: flex;
      flex-direction: row;
      align-items: center;
      justify-content: flex-start;
      padding: 10px;
      border-bottom: 1px dashed #dbdbdb;
    }

    .item3 {
      display: flex;
      flex-direction: column;
      justify-content: flex-start;
      padding: 10px;
      border-bottom: 1px dashed #dbdbdb;
    }

    .label {
      width: 80px;
    }

    .item {
      width: calc(100% - 80px);
    }

    .infoCon {
      display: flex;
      align-items: center;
      flex-direction: row;
      justify-content: flex-start;

      .con {
        display: flex;
        align-items: center;

        span {
          width: 25px;
        }
      }
    }

    .addBtn {
      width: 60px;
      margin-left: 10px;
    }

    .infoItem {
      display: flex;
      flex-direction: column;
      margin-left: 10px;
      margin-top: 15px;

      .items {
        display: flex;
        flex-direction: row;
        align-items: center;
        margin: 10px;
        padding-bottom: 5px;
        border-bottom: 1px dashed #dbdbdb;

        .name {
          width: 70px;
        }

        .con {
          width: calc(100% - 70px);
          display: flex;
          flex-direction: row;
          align-items: center;

          & div:nth-child(1) {
            margin-right: 30px;
          }
        }
      }
    }
  }
}
</style>

<style lang="scss" scoped>
::v-deep .el-radio {
  width: 65px !important;
  margin: 15px 0px 10px 5px;
}
</style>